import java.awt.event.*;
import java.awt.*;
import javax.swing.*;

class RAMActionListener implements ActionListener
{

    UserInterface owner;
    SearchDialog sdialog;

    String username = "db2admin"; // Need you database Username and password
    String password = "crossbow";
    String database = "RENTMOV";

        Toolkit tk;
        Dimension d;

    RAMActionListener(UserInterface owner){
        this.owner = owner;

        tk = Toolkit.getDefaultToolkit();
        d = tk.getScreenSize();
    }

    public void actionPerformed(ActionEvent e){

        if(e.getActionCommand().equals("clientHistory")){


            String SQLStatement = "select H.title, H.director," +
            " H.releasedate, H.renteddate, H.returndate from" +
            " history H where H.mship#=" + owner.getMShip();

            DBQTable dbq = new DBQTable(database); // Need you database name
            JScrollPane scroll;
            JDialog view = new JDialog();
            Container c = view.getContentPane();

            try{
                JTable table = dbq.getTable(username,password,
                                SQLStatement);
                scroll = new JScrollPane(table);
                c.add(scroll);
                c.validate();
                view.setSize(500, 400);
                view.setLocation((d.width/2)-250, (d.height/2)-200);
                view.setVisible(true);
            }catch (Exception x){
                x.printStackTrace();
            }

        } else if (e.getActionCommand().equals("search")){
            sdialog = new SearchDialog(owner,username,password,database);

        }else if (e.getActionCommand().equals("24")){

            String SQLStatement = "SELECT M.MNAME, H.TITLE" +
            " FROM HISTORY H INNER JOIN MEMBERS M" +
            " ON H.MSHIP# = M.MSHIP#" +
            " WHERE H.RENTEDDATE = (CURRENT DATE - 1 DAYS) OR H.RENTEDDATE = CURRENT DATE" +
            owner.getMShip();

            DBQTable dbq = new DBQTable(database); // Need your database name
            JScrollPane scroll;
            JDialog view = new JDialog();
            Container c = view.getContentPane();

            try{
                JTable table = dbq.getTable(username,password,
                                SQLStatement);
                scroll = new JScrollPane(table);
                c.add(scroll);
                c.validate();
                view.setSize(500, 400);
                view.setLocation((d.width/2)-250, (d.height/2)-200);
                view.setVisible(true);
            }catch (Exception x){
                x.printStackTrace();
            }
        }else if (e.getActionCommand().equals("freq")){

            String SQLStatement = "SELECT M.MNAME FROM MEMBERS M INNER JOIN" +
            "(SELECT H.MSHIP# AS MID#, COUNT(H.RENTEDDATE) AS TotalRented, COUNT(H.RETURNDATE)" +
            "AS TotalReturned FROM HISTORY H WHERE H.RENTEDDATE >= (CURRENT DATE - 3 MONTHS)"+
            "AND H.RETURNDATE >= (CURRENT DATE - 3 MONTHS) GROUP BY H.MSHIP#)" +
            "ON MID# = M.MSHIP# WHERE TotalRented >= 15 AND TotalReturned >= 15" + owner.getMShip();

            DBQTable dbq = new DBQTable(database); // Need your database name
            JScrollPane scroll;
            JDialog view = new JDialog();
            Container c = view.getContentPane();

            try{
                JTable table = dbq.getTable(username,password,
                                SQLStatement);
                scroll = new JScrollPane(table);
                c.add(scroll);
                c.validate();
                view.setSize(500, 400);
                view.setLocation((d.width/2)-250, (d.height/2)-200);
                view.setVisible(true);
            }catch (Exception x){
                x.printStackTrace();
            }

        }else if (e.getActionCommand().equals("ADDMOVIE")){

            System.out.println("ADDMOVIE");


        }else if (e.getActionCommand().equals("df")){
            new DemandFactorDialog("Nys","bighouse");

        }else if (e.getActionCommand().equals("manageUsers")){

        	new ManageUser();

        }else{
            System.out.println("No Action Command Found");
        }
    }

}
